<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>go语言学习笔记（一） | Hui</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101pack">
<meta property="og:type" content="article">
<meta property="og:title" content="go语言学习笔记（一）">
<meta property="og:url" content="http://mhuihui.oschina.io/m-pages/2017/01/12/golang环境搭建/index.html">
<meta property="og:site_name" content="Hui">
<meta property="og:description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101pack">
<meta property="og:updated_time" content="2017-02-10T03:36:00.268Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="go语言学习笔记（一）">
<meta name="twitter:description" content="123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101pack">
  
    <link rel="alternate" href="/atom.xml" title="Hui" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/m-pages/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/m-pages/" id="logo">Hui</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/m-pages/">Home</a>
        
          <a class="main-nav-link" href="/m-pages/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://mhuihui.oschina.io/m-pages"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-golang环境搭建" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/m-pages/2017/01/12/golang环境搭建/" class="article-date">
  <time datetime="2017-01-12T12:11:38.000Z" itemprop="datePublished">2017-01-12</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      go语言学习笔记（一）
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<figure class="highlight go"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">package</span> main</div><div class="line"></div><div class="line"><span class="keyword">import</span> (</div><div class="line">	<span class="string">"fmt"</span></div><div class="line">	<span class="string">"unsafe"</span></div><div class="line">)</div><div class="line"></div><div class="line"><span class="keyword">var</span> a <span class="keyword">string</span> = <span class="string">"12"</span></div><div class="line"><span class="keyword">var</span> b = <span class="number">12</span></div><div class="line"><span class="keyword">var</span> c <span class="keyword">int</span></div><div class="line"><span class="keyword">var</span> (</div><div class="line">	str1      = <span class="string">"123456789"</span></div><div class="line">	name1 <span class="keyword">int</span> = <span class="built_in">len</span>(str1)</div><div class="line">	name2     = unsafe.Sizeof(str1)</div><div class="line">)</div><div class="line"></div><div class="line"><span class="keyword">const</span> PI = <span class="number">3</span></div><div class="line"></div><div class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</div><div class="line">	<span class="comment">// 你好世界</span></div><div class="line">	<span class="comment">/*你好世界*/</span></div><div class="line">	fmt.Println(<span class="string">"你好;世界"</span>)</div><div class="line">	c = <span class="number">100</span></div><div class="line">	fmt.Printf(a, b, c)</div><div class="line">	fmt.Println(name1)</div><div class="line">	fmt.Println(name2)</div><div class="line">	<span class="keyword">var</span> o = PI * c</div><div class="line">	fmt.Println(o)</div><div class="line"></div><div class="line">	<span class="keyword">const</span> (</div><div class="line">		a = <span class="literal">iota</span> <span class="comment">//0</span></div><div class="line">		b        <span class="comment">//1</span></div><div class="line">		c        <span class="comment">//2</span></div><div class="line">		d = <span class="string">"ha"</span> <span class="comment">//独立值，iota += 1</span></div><div class="line">		e        <span class="comment">//"ha"   iota += 1</span></div><div class="line">		f = <span class="number">100</span>  <span class="comment">//iota +=1</span></div><div class="line">		g        <span class="comment">//100  iota +=1</span></div><div class="line">		h = <span class="literal">iota</span> <span class="comment">//7,恢复计数</span></div><div class="line">		i        <span class="comment">//8</span></div><div class="line">	)</div><div class="line">	fmt.Println(<span class="string">"start"</span>, a, b, c, d, e, f, g, h, i)</div><div class="line"></div><div class="line">	<span class="keyword">var</span> demo1 <span class="keyword">bool</span> = <span class="literal">true</span></div><div class="line">	<span class="keyword">var</span> demo2 = <span class="literal">false</span></div><div class="line"></div><div class="line">	<span class="keyword">if</span> demo1 &amp;&amp; !demo2 &#123;</div><div class="line">		fmt.Println(<span class="string">"TRUE"</span>)</div><div class="line">	&#125; <span class="keyword">else</span> &#123;</div><div class="line">		fmt.Println(<span class="string">"中国"</span>)</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="keyword">var</span> ptr *<span class="keyword">int</span></div><div class="line">	ptr = &amp;o</div><div class="line">	fmt.Println(ptr)</div><div class="line">	fmt.Println(*ptr)</div><div class="line">	<span class="keyword">var</span> c1, c2, c3 <span class="keyword">chan</span> <span class="keyword">int</span></div><div class="line">	<span class="keyword">var</span> i1, i2 <span class="keyword">int</span></div><div class="line">	<span class="keyword">select</span> &#123;</div><div class="line">	<span class="keyword">case</span> i1 = &lt;-c1:</div><div class="line">		fmt.Printf(<span class="string">"received "</span>, i1, <span class="string">" from c1\n"</span>)</div><div class="line">	<span class="keyword">case</span> c2 &lt;- i2:</div><div class="line">		fmt.Printf(<span class="string">"sent "</span>, i2, <span class="string">" to c2\n"</span>)</div><div class="line">	<span class="keyword">case</span> i3, ok := (&lt;-c3): <span class="comment">// same as: i3, ok := &lt;-c3</span></div><div class="line">		<span class="keyword">if</span> ok &#123;</div><div class="line">			fmt.Printf(<span class="string">"received "</span>, i3, <span class="string">" from c3\n"</span>)</div><div class="line">		&#125; <span class="keyword">else</span> &#123;</div><div class="line">			fmt.Printf(<span class="string">"c3 is closed\n"</span>)</div><div class="line">		&#125;</div><div class="line">	<span class="keyword">default</span>:</div><div class="line">		fmt.Printf(<span class="string">"no communication\n"</span>)</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	fmt.Println(max(<span class="number">1</span>, <span class="number">2</span>))</div><div class="line">	<span class="keyword">var</span> x, y = swap(<span class="string">"str1"</span>, <span class="string">"str2"</span>)</div><div class="line">	fmt.Println(x, y)</div><div class="line"></div><div class="line">	array()</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">func</span> <span class="title">max</span><span class="params">(num1, num2 <span class="keyword">int</span>)</span> <span class="title">int</span></span> &#123;</div><div class="line">	<span class="keyword">if</span> num1 &gt; num2 &#123;</div><div class="line">		<span class="keyword">return</span> <span class="number">1</span></div><div class="line">	&#125; <span class="keyword">else</span> <span class="keyword">if</span> num1 &lt; num2 &#123;</div><div class="line">		<span class="keyword">return</span> <span class="number">-1</span></div><div class="line">	&#125; <span class="keyword">else</span> &#123;</div><div class="line">		<span class="keyword">return</span> <span class="number">0</span></div><div class="line">	&#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">func</span> <span class="title">swap</span><span class="params">(str1, str2 <span class="keyword">string</span>)</span> <span class="params">(<span class="keyword">string</span>, <span class="keyword">string</span>)</span></span> &#123;</div><div class="line">	<span class="keyword">return</span> str2, str1</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">func</span> <span class="title">array</span><span class="params">()</span></span> &#123;</div><div class="line">	<span class="keyword">var</span> var_array = []<span class="keyword">int</span>&#123;<span class="number">1</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">6</span>, <span class="number">7</span>&#125;</div><div class="line">	fmt.Println(var_array)</div><div class="line"></div><div class="line">	<span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="built_in">len</span>(var_array); i++ &#123;</div><div class="line">		fmt.Printf(<span class="string">"var_array[%d] = %d \n"</span>, i, var_array[i])</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://mhuihui.oschina.io/m-pages/m-pages/2017/01/12/golang环境搭建/" data-id="ciyzazase000ss8vgviwp242s" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/m-pages/tags/编程/">编程</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/m-pages/2017/01/12/go语言学习笔记（一）/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          go语言开发环境搭建
        
      </div>
    </a>
  
  
    <a href="/m-pages/2017/01/11/Struts总结/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Struts总结</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/ide/">ide</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/编程/">编程</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/设计/">设计</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/m-pages/tags/ide/" style="font-size: 13.33px;">ide</a> <a href="/m-pages/tags/linux/" style="font-size: 16.67px;">linux</a> <a href="/m-pages/tags/编程/" style="font-size: 20px;">编程</a> <a href="/m-pages/tags/设计/" style="font-size: 10px;">设计</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2017/01/">January 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2016/12/">December 2016</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/m-pages/2017/02/10/go语言学习笔记（四)/">go语言学习笔记（四）</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/02/10/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/14/go语言学习笔记（三）/">go语言学习笔记（三）</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/13/go语言学习笔记（二）/">go语言学习笔记（二）结构体和切片</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/12/go语言学习笔记（一）/">go语言开发环境搭建</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 hui<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/m-pages/" class="mobile-nav-link">Home</a>
  
    <a href="/m-pages/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/m-pages/fancybox/jquery.fancybox.css">
  <script src="/m-pages/fancybox/jquery.fancybox.pack.js"></script>


<script src="/m-pages/js/script.js"></script>

  </div>
</body>
</html>